package com.review.reviewsb.handler;

import com.review.reviewsb.utils.JsonData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: reviewSb
 * @description: 自定义全局异常处理
 * @author: YaoZhiLi
 * @create: 2021-07-04 09:36
 */

//@RestControllerAdvice
    @ControllerAdvice
public class CustomExHanlder {
   /* @ExceptionHandler(value = Exception.class)
    JsonData handlerException(Exception e, HttpServletRequest request){
        return JsonData.buildError("服务端出现异常了",-2);
    }*/
   @ExceptionHandler(value = Exception.class)
   Object handlerException(Exception e, HttpServletRequest request){
       ModelAndView modelAndView = new ModelAndView();
       modelAndView.setViewName("error.html");
       modelAndView.addObject("msg",e.getMessage());
       return modelAndView;
   }
}